<?php
class Tab_IndexController extends YouNet_Controller_Action
{
    public function preDispatch()
    {
        parent::preDispatch();                                
    }
	
    public function init()
	{
        parent::init();		
        $this->_helper->layout->setLayout('tab_facebook');
        
        //set value session :using for case change content type in backend then load new content on fan page
        $id_page = $this->_social->getIdPage(); 
        $db_configs = Core_Model_DbTable_Configs::getInstance();
        $ss_info = new Zend_Session_Namespace('config_info');
        $ss_like = new Zend_Session_Namespace('like');
        
        $ss_info->updated_date   = $db_configs->get_newest_updated_date($id_page);
        $ss_like->is_liked= $this->_social->hasLikedPage();
	}   
    
    public function indexAction()
    {  
        $this->start_cache_page();
        
        $id_page = $this->_social->getIdPage(); 
        
        $db_configs = Core_Model_DbTable_Configs::getInstance();
        
        $is_liked = $this->_social->hasLikedPage();
        
        // Get params 
        if ($is_liked ==1 )
        {
            $config_content = $db_configs ->getconfigs($id_page,0);//get config for fans
        }
        else 
        {
            $config_content = $db_configs ->getconfigs($id_page,1);//get config for non fans
            
            if (!$config_content)//non fans is off or not set any thing
            {
                $config_content = $db_configs ->getconfigs($id_page,0);//get config for fans
            }
        }
        
        $this->view->config_content = $config_content;
    }
    
    public function start_cache_page(){
        $frontendOptions = array(
            'debug_header' => false,
            'default_options' => array(
               'cache' => true,
                'cache_with_get_variables' => true,
                'cache_with_post_variables' => true,
                'cache_with_session_variables' => true,
                'cache_with_files_variables' => true,
                'cache_with_cookie_variables' => true,
                //'make_id_with_get_variables' => false,
                'make_id_with_post_variables' => false,
                //'make_id_with_session_variables' => false,
                //'make_id_with_files_variables' => false,
                'make_id_with_cookie_variables' => false
           ) 
        );

        $backendOptions = array(
            'cache_dir' => CACHE_PATH."/page"
        );

        $cache = Zend_Cache::factory('Page','File',$frontendOptions,$backendOptions);

        $cache->start();
    }
}